package com.kgc.provider;

import com.alibaba.dubbo.config.annotation.Service;
import com.kgc.api.user.FootPrintApi;

import com.kgc.bean.Footprint;
import com.kgc.domain.FootprintExample;
import com.kgc.mapper.FootprintMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Classname FootPrintProvider
 * @Description TODO
 * @Date 2021/6/20 21:22
 * @Created by 17402
 */
@Service
@Slf4j
public class FootPrintProvider implements FootPrintApi {

    @Autowired
    private FootprintMapper footprintMapper;
    @Override
    public Footprint findFootprint(String goodsId, Integer userId) {
        FootprintExample footprintExample=new FootprintExample();
        FootprintExample.Criteria criteria=footprintExample.createCriteria();
        criteria.andFootprintGoodsIdEqualTo(goodsId);
        criteria.andUserIdEqualTo(userId);
        if(footprintMapper.selectByExample(footprintExample).size()>0){
            return footprintMapper.selectByExample(footprintExample).get(0);
        }
        return null;
    }

    @Override
    public Boolean addFootPrint(Footprint footprint) {
        if(footprintMapper.insert(footprint)==1){
            return true;
        }
        return false;
    }

    @Override
    public void updateFootTime(Footprint footprint) {
        footprintMapper.updateByPrimaryKey(footprint);
    }

    @Override
    public List<Footprint> findFootprintByUserId(Integer userId) {
        FootprintExample footprintExample=new FootprintExample();
        footprintExample.setOrderByClause("footprint_time DESC");
        FootprintExample.Criteria criteria=footprintExample.createCriteria();
        criteria.andUserIdEqualTo(userId);


        return footprintMapper.selectByExample(footprintExample);
    }
}
